package com.jhhc.Config;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;


@Configuration
@MapperScan(value = {"com.jhhc.Weathers.Picture.Dao","com.jhhc.Weathers.datasupplement.dao"}, sqlSessionFactoryRef = "sqlSessionFactory3")
public class WeatherConfig {
        /**
         * 和总配置文件注入bean名称一致 其他无需修改
         */
        @Autowired
        @Qualifier("weatherDataSource")
        private DataSource ds3;

        @Bean(name = "sqlSessionFactory3")
        @Primary
        public SqlSessionFactory sqlSessionFactory3() throws Exception {
            SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
            sqlSessionFactoryBean.setDataSource(ds3);
            return sqlSessionFactoryBean.getObject();
        }

        @Bean
        @Primary
        public SqlSessionTemplate sqlSessionTemplate3() throws Exception {
            return new SqlSessionTemplate(sqlSessionFactory3());
        }



}
